package cn.springcloud.fix.es.service;

import java.util.*;

public class Test1 {

    public static void main(String[] args) {
        int[] nums1 = {1, 2, 1, 2};
        int[] nums2 = {2, 2};

        int[] res = intersection(nums1, nums2);
        System.out.println(11);
    }

    public static int[] intersection(int[] nums1, int[] nums2) {
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        for (int a : nums1) {
            list1.add(a);
        }
        for (int a : nums2) {
            list2.add(a);
        }
        list1.retainAll(list2);
        int[] intersection = new int[nums1.length + nums2.length];
        int i = 0;
        for (Integer a : list1) {
            intersection[i] = a;
            i++;
        }
        return Arrays.copyOfRange(intersection, 0, i - 1);
    }
}
